package top.easyblog.core.dao.auto.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;
import top.easyblog.core.dao.auto.model.UrlMapping;
import top.easyblog.core.dao.auto.model.UrlMappingExample;

@Mapper
@Repository
public interface UrlMappingMapper {
    @SelectProvider(type=UrlMappingSqlProvider.class, method="countByExample")
    long countByExample(UrlMappingExample example);

    @DeleteProvider(type=UrlMappingSqlProvider.class, method="deleteByExample")
    int deleteByExample(UrlMappingExample example);

    @Delete({
        "delete from url_mapping",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into url_mapping (compression_code, source_url, ",
        "tiny_url, source_url_digest, ",
        "tiny_url_digest, description, ",
        "status, create_time, ",
        "update_time)",
        "values (#{compressionCode,jdbcType=VARCHAR}, #{sourceUrl,jdbcType=VARCHAR}, ",
        "#{tinyUrl,jdbcType=VARCHAR}, #{sourceUrlDigest,jdbcType=VARCHAR}, ",
        "#{tinyUrlDigest,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, ",
        "#{status,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{updateTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(UrlMapping record);

    @InsertProvider(type=UrlMappingSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(UrlMapping record);

    @SelectProvider(type=UrlMappingSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="compression_code", property="compressionCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_url", property="sourceUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="tiny_url", property="tinyUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_url_digest", property="sourceUrlDigest", jdbcType=JdbcType.VARCHAR),
        @Result(column="tiny_url_digest", property="tinyUrlDigest", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<UrlMapping> selectByExample(UrlMappingExample example);

    @Select({
        "select",
        "id, compression_code, source_url, tiny_url, source_url_digest, tiny_url_digest, ",
        "description, status, create_time, update_time",
        "from url_mapping",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="compression_code", property="compressionCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_url", property="sourceUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="tiny_url", property="tinyUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_url_digest", property="sourceUrlDigest", jdbcType=JdbcType.VARCHAR),
        @Result(column="tiny_url_digest", property="tinyUrlDigest", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    UrlMapping selectByPrimaryKey(Long id);

    @UpdateProvider(type=UrlMappingSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") UrlMapping record, @Param("example") UrlMappingExample example);

    @UpdateProvider(type=UrlMappingSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") UrlMapping record, @Param("example") UrlMappingExample example);

    @UpdateProvider(type=UrlMappingSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(UrlMapping record);

    @Update({
        "update url_mapping",
        "set compression_code = #{compressionCode,jdbcType=VARCHAR},",
          "source_url = #{sourceUrl,jdbcType=VARCHAR},",
          "tiny_url = #{tinyUrl,jdbcType=VARCHAR},",
          "source_url_digest = #{sourceUrlDigest,jdbcType=VARCHAR},",
          "tiny_url_digest = #{tinyUrlDigest,jdbcType=VARCHAR},",
          "description = #{description,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=TINYINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(UrlMapping record);
}